package exam.model.dao;

import java.util.List;

import exam.common.util.NullCheckUtil;
import exam.common.util.StringUtils;
import exam.model.entity.TAnswerEntity;

public class AnswerDAO extends AbstractDao<TAnswerEntity>{
	
	public AnswerDAO() {
		super(TAnswerEntity.class);
	}
	
	public List<TAnswerEntity> selectByQuestionId(long questionId) {
		String query = "select a from TAnswerEntity a inner join a.questionEntity where a.questionId="+questionId;
		return super.selectList(query);
	}
	
	public List<TAnswerEntity> select002(List<Long> listQuestionId) {
		String query = "select a from TAnswerEntity a where a.questionId in " 
				+ StringUtils.replaceStartAndEndForList(listQuestionId, "(", ")");
		return super.selectList(query);
	}
	
	public TAnswerEntity selectByPk(long id) {
		return super.selectByPk(id);
	}
	
	public void insertAnswer(TAnswerEntity answer) {
		super.insert(answer);
	}
	
	public void updateAnswer(TAnswerEntity answer) {
			super.update(answer);
	}
	
	public boolean deleteAnswer(long id) {
		if (NullCheckUtil.isNUll(selectByPk(id))) {
			return false;
		}
		super.delete(id);
		return true;
	}
}
